package com.link.base.base.logcode.service;

import java.util.Date;
import javax.annotation.Resource;

import com.link.base.base.logcode.dao.mybatis.mapper.LogCodeMapper;
import com.link.base.base.logcode.model.LogCode;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceImpl;
import com.link.core.util.DateUtil;
import com.link.core.util.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 订单明细物流码-订单明细物流码
 *
 * @author 宁蓝昊
 * @date 2019/06/27 11:38
 */
@Service
public class LogCodeServiceImpl extends BasicServiceImpl<LogCode> implements LogCodeService {

    @Resource
    private LogCodeMapper logCodeMapper;

    @Override
    public BasicMapper<LogCode> getBasicMapper() {
        return logCodeMapper;
    }

    @Override
    public void beforInsert(LogCode entity) throws Exception {
        // 针对奖励订单新增物流记录，物流时间为当前时间
        if (StringUtils.isBlank(entity.getLogTime())) {
            entity.setLogTime(DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
        }
        super.beforInsert(entity);
    }

    /**
     * 根据订单行id删除物流行
     * @author 姚江漪
     * @date 2019/08/17 15:03
     */
    @Override
    public void deleteByHeadId(LogCode logCode) throws Exception {
        logCodeMapper.deleteByHeadId(logCode);
    }
}

